import { Request } from '../../../utils/request.js';
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        choosestate: 0,
        choose_name_array: [],
        choose_id_array: [],
        // detailList:[
        //     {
        //         name:'测试'
        //     },
        //     {
        //         name:'测试'
        //     },
        //     {
        //         name:'测试'
        //     },
        // ]
    },

    choose:function(e){
        let index = e.currentTarget.dataset.level;
        let name = e.currentTarget.dataset.choose_name;
        let chooses_id = e.currentTarget.dataset.chooses_id;
        let panduan_name = this.data.choose_name_array.indexOf(name);
        let panduan_id = this.data.choose_id_array.indexOf(chooses_id);
        this.data.detailList.map(function(e,n,m){
            if(e.id == chooses_id){
                if(e.level == 1){
                    return e.level = 1;
                }else{
                    return e.level = 0;
                }
            }
        });

        if(panduan_name == -1){
            this.data.choose_name_array.splice(0, 1, name);
        } else {
            this.data.choose_name_array.splice(0, 1);
        }
        if(panduan_name == -1){
            this.data.choose_id_array.splice(0, 1,chooses_id);
        } else {
            this.data.choose_id_array.splice(0, 1);
        }
        // if(panduan_name != -1){
        //     this.data.choose_name_array.splice(panduan_name, 1);
        // }else{
        //     this.data.choose_name_array.push(name);
        // }
        // if(panduan_id != -1){
        //     this.data.choose_id_array.splice(panduan_id, 1);
        // }else{
        //     this.data.choose_id_array.push(chooses_id);
        // }
        console.log(this.data.choose_name_array);
        console.log(this.data.choose_id_array);

        this.setData({
            detailList: this.data.detailList
        });
    },
    /**
     * 
     * @param {保存用户选择 多项} options 
     */
    btn_2:function(e){
        let choose_id = this.data.choose_id_array.toString();
        let choose_name = this.data.choose_name_array.toString();
        let choose_object = {
            choose_id: choose_id,
            choose_name: choose_name
        }
        console.log(choose_object);
         const eventChannel = this.getOpenerEventChannel();
         eventChannel.emit('gj_danxuan', choose_object);
         wx.navigateBack({
            delta: 1,
          })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('gj_danxuan', function(data) {
            console.log(data);
            this.columid = data.columid;
        }.bind(this));
        //
        new Request('Zhaon_Update_Height/GetHeightInfo').request(
        () => {
            return {
                openid: app.globalData.openid, //用户的openid
                choose_id: this.columid
            }
        },
        (res) => {
            this.setData({
                detailList: res.data.data
            })
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})